#!/usr/bin/env python


#
# Imports
#

import os
import cgi

from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app

import auth

import datastore

#
# Request handlers
#

class SettingsPage(webapp.RequestHandler):
    def get(self):
	# Authorize users from datastore list of allowed emails
        template_values = {}
        if auth.request_authorize(self, template_values, '/settings') == False:
            return

        # Page specific code

        user = users.get_current_user() # this always returns something cuz we authorize only non-anonymous

        nickname = user.nickname()
        email = user.email()
        greeting = 'Hi there, ' + nickname + ':) '

        template_values['greeting'] = greeting

        # Generate html from django template.
        auth.request_generate(self,'templates/404.html',template_values)

##
## Url switching table
##

application = webapp.WSGIApplication([
        ('/settings', SettingsPage),
        ], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
